package anagram;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.naming.ldap.SortControl;

public class search {
	public static void main(String[] args) {
		String[][] s = new String[30000][10000]; //每行第一个记录当行的字典序单词
		int[] record = new int[30000];//记录当行同构异序单词的数量
		int n=0; //记录当前同构异序族的数量
		for(int j=0;j<1000;j++){
			record[j]=0;
		}
		try {
			FileReader fr =new FileReader("G:/test.txt");
			BufferedReader br=new BufferedReader(fr);
			try{
				String rl=br.readLine();
				while(rl!=null) {
					String temp=sort(rl);
					boolean b=false; //是否前面已经有了同构单词
					for(int i=0;i<n;i++){
						if(s[i][0].equals(temp)){
							s[i][record[i]+1]=rl;
							b=true;
							record[i]++;
							break;
						}
					}
					if(!b){
						s[n][0]=temp;
						s[n][1]=rl;
						record[n]++;
						n++;
					}
					rl=br.readLine();
				}
				int max=0;
				int maxcol=0;
				for(int j=0;j<1000;j++){
					if(record[j]>max){
						max=record[j];
						maxcol=j;
					}
				}
				for(int d=1;d<=record[maxcol];d++){
					System.out.print(s[maxcol][d]+" ");
				}
				System.out.print("num :"+record[maxcol]);
				/*for(int k=0;k<n;k++){
					for(int d=1;d<=record[k];d++){
						System.out.print(s[k][d]+" ");
					}
					System.out.print("num :"+record[k]);
					System.out.println();
				}*/
				
			}
			catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
			}
		}
		catch(Exception e) {
			e.printStackTrace();
		}
	}

	private static String sort(String s) {
		// TODO Auto-generated method stub
		char[] c=s.toCharArray();
		Arrays.sort(c); //字典序排列
		return String.valueOf(c);
	}
	
	

}
